package com.example.portdemo.view;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModel;

import com.example.portdemo.R;
import com.example.portdemo.date.api.DatabaseClient;
import com.example.portdemo.date.api.RetrofitClient;
import com.example.portdemo.date.model.NewsEntity;
import com.example.portdemo.date.repository.NewsRepositoryImpl;
import com.example.portdemo.service.NewsApiService;
import com.example.portdemo.service.NewsRepository;
import com.example.portdemo.viewModel.NewsViewModel;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class NewsActivity extends AppCompatActivity {

    private NewsViewModel newsViewModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news);

        // 创建ViewModel
        NewsRepository newsRepository = new NewsRepositoryImpl(
                RetrofitClient.getInstance().create(String.valueOf(NewsApiService.class)),
                DatabaseClient.getInstance(this).newsDao()
        );
        newsViewModel = new NewsViewModel(newsRepository);

        // 加载新闻列表
        newsViewModel.getNewsList(new Callback<List<NewsEntity>>() {
            @Override
            public void onResponse(Call<List<NewsEntity>> call, Response<List<NewsEntity>> response) {

            }

            @Override
            public void onFailure(Call<List<NewsEntity>> call, Throwable throwable) {

            }
        });
    }
}